package handler

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
)

type uError string

func (e uError) Error() string {
	return string(e)
}
func (e uError) Message() string {
	return e.Error()
}

func HandleHttp(writer http.ResponseWriter, request *http.Request) error {
	if request.URL.Path == "/" {
		return uError("Null url is invalid")
	}
	path := "httpserver/www" + request.URL.Path[:]
	fmt.Println(path)
	file, err := os.Open(path)
	if err != nil {
		return err
	}
	defer file.Close()
	all, err := ioutil.ReadAll(file)
	fmt.Println(all)
	if err != nil {
		return err
	}
	writer.Write(all)
	return nil
}
